package ce.com.cenewbluesdk.entity.k3;

import android.os.Parcel;
import android.os.Parcelable;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;

/**
 * Created by Administrator on 2015/7/2.
 * typedef struct
 * {
 * unsigned char phone_type;  //手机类型，1：安卓；2：苹果
 * unsigned char pair_type;	//配对类型，0：无配对；1：本地配对；2：蓝牙密码配对；
 * //3：重连
 * unsigned char random[4];   //验证码为4个字节的ASCII字符
 * }ble_pair_connect_struct;
 */
public class Send_Bt_NeedPair_T_K3 extends BaseData implements Parcelable {

    public static final byte PHONE_ANDROID = 1;
    public static final byte PAIR_TYPE_TWO_CODE = 1;
    public static final byte PAIR_TYPE_NUM = 2;

    byte phone_type; //安卓手机：1  苹果手机：2
    byte pair_type; //配对类型，0：无配对；1：本地配对；2：蓝牙密码配对
    byte[] random = new byte[4];  //验证码
    byte display_type; //1：二维码显示；2：数字显示；

    public Send_Bt_NeedPair_T_K3(byte phone_type, byte pair_type, byte[] rdm, byte display_type) {
        this.phone_type = phone_type;
        this.pair_type = pair_type;
        System.arraycopy(rdm, 0, random, 0, rdm.length);
        this.display_type = display_type;
    }

    protected Send_Bt_NeedPair_T_K3(Parcel in) {
        phone_type = in.readByte();
        pair_type = in.readByte();
        random = in.createByteArray();
        display_type = in.readByte();
    }

    public static final Creator<Send_Bt_NeedPair_T_K3> CREATOR = new Creator<Send_Bt_NeedPair_T_K3>() {
        @Override
        public Send_Bt_NeedPair_T_K3 createFromParcel(Parcel in) {
            return new Send_Bt_NeedPair_T_K3(in);
        }

        @Override
        public Send_Bt_NeedPair_T_K3[] newArray(int size) {
            return new Send_Bt_NeedPair_T_K3[size];
        }
    };

    public byte[] getRandom() {
        return random;
    }

    public void setRandom(byte[] random) {
        this.random = random;
    }

    public byte[] getBytes() {
        byte[] bytes = new byte[3 + random.length];
        bytes[0] = phone_type;
        bytes[1] = pair_type;
        System.arraycopy(random, 0, bytes, 2, random.length);
        bytes[2 + random.length] = display_type;
        return bytes;
    }

    public static int getItemSize() {
        return 7;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(phone_type);
        dest.writeByte(pair_type);
        dest.writeByteArray(random);
        dest.writeByte(display_type);
    }

    @Override
    public CEDevData toCEDevData() {
        CEDevData data=new CEDevData(CEBC.CMD_SEND_TYPE,CEBC.K3.DATA_TYPE_PAIR_CONNECT);
        data.setData(getBytes());
        data.setItemL(getItemSize());
        data.setItemNumber(1);
        return data;
    }
}
